home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / tcl / tcl67.lha / tcl6.7 / tclUnix.h < prev    next >
C/C++ Source or Header  |  1993-02-10  |  8KB  |  318 lines

  1. /*
  2.  * tclUnix.h --
  3.  *
  4.  *    This file reads in UNIX-related header files and sets up
  5.  *    UNIX-related macros for Tcl's UNIX core.  It should be the
  6.  *    only file that contains #ifdefs to handle different flavors
  7.  *    of UNIX.  This file sets up the union of all UNIX-related
  8.  *    things needed by any of the Tcl core files.  This file
  9.  *    depends on configuration #defines in tclConfig.h
  10.  *
  11.  *    The material in this file was originally contributed by
  12.  *    Karl Lehenbauer, Mark Diekhans and Peter da Silva.
  13.  *
  14.  * Copyright 1991 Regents of the University of California
  15.  * Permission to use, copy, modify, and distribute this
  16.  * software and its documentation for any purpose and without
  17.  * fee is hereby granted, provided that this copyright
  18.  * notice appears in all copies.  The University of California
  19.  * makes no representations about the suitability of this
  20.  * software for any purpose.  It is provided "as is" without
  21.  * express or implied warranty.
  22.  *
  23.  * $Header: /user6/ouster/tcl/RCS/tclUnix.h,v 1.31 92/12/23 16:49:17 ouster Exp $ SPRITE (Berkeley)
  24.  */
  25.  
  26. #ifndef _TCLUNIX
  27. #define _TCLUNIX
  28.  
  29. /*
  30.  * The following #defines are used to distinguish between different
  31.  * UNIX systems.  These #defines are normally set by the "config" script
  32.  * based on information it gets by looking in the include and library
  33.  * areas.  The defaults below are for BSD-based systems like SunOS
  34.  * or Ultrix.
  35.  *
  36.  * TCL_GETTOD -            1 means there exists a library procedure
  37.  *                "gettimeofday" (e.g. BSD systems).  0 means
  38.  *                have to use "times" instead.
  39.  * TCL_GETWD -            1 means there exists a library procedure
  40.  *                "getwd" (e.g. BSD systems).  0 means
  41.  *                have to use "getcwd" instead.
  42.  * TCL_SYS_ERRLIST -        1 means that the array sys_errlist is
  43.  *                defined as part of the C library.
  44.  * TCL_SYS_TIME_H -        1 means there exists an include file
  45.  *                <sys/time.h> (e.g. BSD derivatives).
  46.  * TCL_SYS_WAIT_H -        1 means there exists an include file
  47.  *                <sys/wait.h> that defines constants related
  48.  *                to the results of "wait".
  49.  * TCL_UNION_WAIT -        1 means that the "wait" system call returns
  50.  *                a structure of type "union wait" (e.g. BSD
  51.  *                systems).  0 means "wait" returns an int
  52.  *                (e.g. System V and POSIX).
  53.  * TCL_PID_T -            1 means that <sys/types> defines the type
  54.  *                pid_t.  0 means that it doesn't.
  55.  * TCL_UID_T -            1 means that <sys/types> defines the type
  56.  *                uid_t.  0 means that it doesn't.
  57.  */
  58.  
  59. #define TCL_GETTOD 1
  60. #define TCL_GETWD 1
  61. #define TCL_SYS_ERRLIST 1
  62. #define TCL_SYS_TIME_H 1
  63. #define TCL_SYS_WAIT_H 1
  64. #define TCL_UNION_WAIT 1
  65. #define TCL_PID_T 1
  66. #define TCL_UID_T 1
  67.  
  68. #include <errno.h>
  69. #include <fcntl.h>
  70. #include <limits.h>
  71. #include <pwd.h>
  72. #include <signal.h>
  73. #include <sys/param.h>
  74. #include <sys/types.h>
  75. #include <dirent.h>
  76. #include <sys/file.h>
  77. #include <sys/stat.h>
  78. #if TCL_SYS_TIME_H
  79. #   include <sys/time.h>
  80. #else
  81. #   include <time.h>
  82. #endif
  83. #if TCL_SYS_WAIT_H
  84. #   include <sys/wait.h>
  85. #endif
  86.  
  87. /*
  88.  * Not all systems declare the errno variable in errno.h. so this
  89.  * file does it explicitly.  The list of system error messages also
  90.  * isn't generally declared in a header file anywhere.
  91.  */
  92.  
  93. extern int errno;
  94. extern int sys_nerr;
  95. extern char *sys_errlist[];
  96.  
  97. /*
  98.  * The type of the status returned by wait varies from UNIX system
  99.  * to UNIX system.  The macro below defines it:
  100.  */
  101.  
  102. #if TCL_UNION_WAIT
  103. #   define WAIT_STATUS_TYPE union wait
  104. #else
  105. #   define WAIT_STATUS_TYPE int
  106. #endif
  107.  
  108. /*
  109.  * Supply definitions for macros to query wait status, if not already
  110.  * defined in header files above.
  111.  */
  112.  
  113. #ifndef WIFEXITED
  114. #   define WIFEXITED(stat)  (((*((int *) &(stat))) & 0xff) == 0)
  115. #endif
  116.  
  117. #ifndef WEXITSTATUS
  118. #   define WEXITSTATUS(stat) (((*((int *) &(stat))) >> 8) & 0xff)
  119. #endif
  120.  
  121. #ifndef WIFSIGNALED
  122. #   define WIFSIGNALED(stat) (((*((int *) &(stat)))) && ((*((int *) &(stat))) == ((*((int *) &(stat))) & 0x00ff)))
  123. #endif
  124.  
  125. #ifndef WTERMSIG
  126. #   define WTERMSIG(stat)    ((*((int *) &(stat))) & 0x7f)
  127. #endif
  128.  
  129. #ifndef WIFSTOPPED
  130. #   define WIFSTOPPED(stat)  (((*((int *) &(stat))) & 0xff) == 0177)
  131. #endif
  132.  
  133. #ifndef WSTOPSIG
  134. #   define WSTOPSIG(stat)    (((*((int *) &(stat))) >> 8) & 0xff)
  135. #endif
  136.  
  137. /*
  138.  * Supply macros for seek offsets, if they're not already provided by
  139.  * an include file.
  140.  */
  141.  
  142. #ifndef SEEK_SET
  143. #   define SEEK_SET 0
  144. #endif
  145.  
  146. #ifndef SEEK_CUR
  147. #   define SEEK_CUR 1
  148. #endif
  149.  
  150. #ifndef SEEK_END
  151. #   define SEEK_END 2
  152. #endif
  153.  
  154. /*
  155.  * The stuff below is needed by the "time" command.  If this
  156.  * system has no gettimeofday call, then must use times and the
  157.  * CLK_TCK #define (from sys/param.h) to compute elapsed time.
  158.  * Unfortunately, some systems only have HZ and no CLK_TCK, and
  159.  * some might not even have HZ.
  160.  */
  161.  
  162. #if ! TCL_GETTOD
  163. #   include <sys/times.h>
  164. #   include <sys/param.h>
  165. #   ifndef CLK_TCK
  166. #       ifdef HZ
  167. #           define CLK_TCK HZ
  168. #       else
  169. #           define CLK_TCK 60
  170. #       endif
  171. #   endif
  172. #endif
  173.  
  174. /*
  175.  * Define access mode constants if they aren't already defined.
  176.  */
  177.  
  178. #ifndef F_OK
  179. #    define F_OK 00
  180. #endif
  181. #ifndef X_OK
  182. #    define X_OK 01
  183. #endif
  184. #ifndef W_OK
  185. #    define W_OK 02
  186. #endif
  187. #ifndef R_OK
  188. #    define R_OK 04
  189. #endif
  190.  
  191. /*
  192.  * On systems without symbolic links (i.e. S_IFLNK isn't defined)
  193.  * define "lstat" to use "stat" instead.
  194.  */
  195.  
  196. #ifndef S_IFLNK
  197. #   define lstat stat
  198. #endif
  199.  
  200. /*
  201.  * Define macros to query file type bits, if they're not already
  202.  * defined.
  203.  */
  204.  
  205. #ifndef S_ISREG
  206. #   ifdef S_IFREG
  207. #       define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
  208. #   else
  209. #       define S_ISREG(m) 0
  210. #   endif
  211. # endif
  212. #ifndef S_ISDIR
  213. #   ifdef S_IFDIR
  214. #       define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
  215. #   else
  216. #       define S_ISDIR(m) 0
  217. #   endif
  218. # endif
  219. #ifndef S_ISCHR
  220. #   ifdef S_IFCHR
  221. #       define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
  222. #   else
  223. #       define S_ISCHR(m) 0
  224. #   endif
  225. # endif
  226. #ifndef S_ISBLK
  227. #   ifdef S_IFBLK
  228. #       define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
  229. #   else
  230. #       define S_ISBLK(m) 0
  231. #   endif
  232. # endif
  233. #ifndef S_ISFIFO
  234. #   ifdef S_IFIFO
  235. #       define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
  236. #   else
  237. #       define S_ISFIFO(m) 0
  238. #   endif
  239. # endif
  240. #ifndef S_ISLNK
  241. #   ifdef S_IFLNK
  242. #       define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
  243. #   else
  244. #       define S_ISLNK(m) 0
  245. #   endif
  246. # endif
  247. #ifndef S_ISSOCK
  248. #   ifdef S_IFSOCK
  249. #       define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
  250. #   else
  251. #       define S_ISSOCK(m) 0
  252. #   endif
  253. # endif
  254.  
  255. /*
  256.  * Make sure that MAXPATHLEN is defined.
  257.  */
  258.  
  259. #ifndef MAXPATHLEN
  260. #   ifdef PATH_MAX
  261. #       define MAXPATHLEN PATH_MAX
  262. #   else
  263. #       define MAXPATHLEN 2048
  264. #   endif
  265. #endif
  266.  
  267. /*
  268.  * Define pid_t and uid_t if they're not already defined.
  269.  */
  270.  
  271. #if ! TCL_PID_T
  272. #   define pid_t int
  273. #endif
  274. #if ! TCL_UID_T
  275. #   define uid_t int
  276. #endif
  277.  
  278. /*
  279.  * Variables provided by the C library:
  280.  */
  281.  
  282. #if defined(_sgi) || defined(__sgi)
  283. #define environ _environ
  284. #endif
  285. extern char **environ;
  286.  
  287. /*
  288.  * Library procedures used by Tcl but not declared in a header file:
  289.  */
  290.  
  291. #ifndef _CRAY
  292. extern int    access       _ANSI_ARGS_((CONST char *path, int mode));
  293. extern int    chdir       _ANSI_ARGS_((CONST char *path));
  294. extern int    close       _ANSI_ARGS_((int fd));
  295. extern int    dup2       _ANSI_ARGS_((int src, int dst));
  296. extern void    endpwent   _ANSI_ARGS_((void));
  297. extern int    execvp       _ANSI_ARGS_((CONST char *name, char **argv));
  298. extern void    _exit        _ANSI_ARGS_((int status));
  299. extern pid_t    fork       _ANSI_ARGS_((void));
  300. extern uid_t    geteuid       _ANSI_ARGS_((void));
  301. extern pid_t    getpid       _ANSI_ARGS_((void));
  302. extern char *    getcwd        _ANSI_ARGS_((char *buffer, int size));
  303. extern char *    getwd         _ANSI_ARGS_((char *buffer));
  304. extern int    kill       _ANSI_ARGS_((pid_t pid, int sig));
  305. extern long    lseek       _ANSI_ARGS_((int fd, int offset, int whence));
  306. extern char *    mktemp       _ANSI_ARGS_((char *template));
  307. #if !(defined(sparc) || defined(_IBMR2))
  308. extern int    open       _ANSI_ARGS_((CONST char *path, int flags, ...));
  309. #endif
  310. extern int    pipe       _ANSI_ARGS_((int *fdPtr));
  311. extern int    read       _ANSI_ARGS_((int fd, char *buf, int numBytes));
  312. extern int    readlink   _ANSI_ARGS_((CONST char *path, char *buf, int size));
  313. extern int    unlink        _ANSI_ARGS_((CONST char *path));
  314. extern int    write       _ANSI_ARGS_((int fd, char *buf, int numBytes));
  315. #endif /* _CRAY */
  316.  
  317. #endif /* _TCLUNIX */
  318.